//
//  AlertViewController.swift
//  DemoUI
// 警告视图控制器的应用
//  Created by 白瑾浩 on 2022/1/8.
//

import UIKit

class AlertViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        
    
        let mUIButton = UIButton(type: UIButton.ButtonType.system)
        mUIButton.frame = CGRect(x: 0, y: 100, width: 200, height: 30)
        mUIButton.setTitle("alert弹窗", for: UIControl.State.normal)
        mUIButton.addTarget(self, action: #selector(alert), for: UIControl.Event.touchUpInside)
        self.view.addSubview( mUIButton )
        
        let mUIButton1 = UIButton(type: UIButton.ButtonType.system)
        mUIButton1.frame = CGRect(x: 0, y: 140, width:200, height: 30)
        mUIButton1.setTitle("alert弹窗竖排", for: UIControl.State.normal)
        mUIButton1.addTarget(self, action: #selector(alert2), for: UIControl.Event.touchUpInside)
        self.view.addSubview( mUIButton1 )
        
        
        let mUIButton2 = UIButton(type: UIButton.ButtonType.system)
        mUIButton2.frame = CGRect(x: 200, y: 140, width:200, height: 30)
        mUIButton2.setTitle("警告编辑框", for: UIControl.State.normal)
        mUIButton2.addTarget(self, action: #selector(alert3), for: UIControl.Event.touchUpInside)
        self.view.addSubview( mUIButton2 )
        
        let mUIButton3 = UIButton(type: UIButton.ButtonType.system)
        mUIButton3.frame = CGRect(x: 10, y: 180, width:200, height: 30)
        mUIButton3.setTitle("创建抽屉弹窗", for: UIControl.State.normal)
        mUIButton3.addTarget(self, action: #selector(alert4), for: UIControl.Event.touchUpInside)
        self.view.addSubview( mUIButton3 )
        
        
        // Do any additional setup after loading the view.
    }
    //确认按钮
    @objc func alert(){
        
       let mUIAlertController =  UIAlertController(title: "我是警告弹框", message: "这里填写内功", preferredStyle: .alert)
        
        let action = UIAlertAction(title: "确定", style: UIAlertAction.Style.default) { (action) in
            print( "用户点击了按钮一" )
        }
//        let action2 = UIAlertAction(title: "取消", style: UIAlertAction.Style.default) { (action) in
//            print( "用户点击了按钮一" )
//        }
    
        mUIAlertController.addAction( action )
        //mUIAlertController.addAction( action2 )
        self.present(mUIAlertController, animated: true) {
            print("完成")
        }
        
    }
    //竖排按钮 超过2个
    @objc func alert2(){
        
        let mUIAlertController =  UIAlertController(title: "我是警告弹框", message: "这里填写内功", preferredStyle: .alert)
         
         let action = UIAlertAction(title: "确定", style: UIAlertAction.Style.default) { (action) in
             print( "用户点击了按钮一" )
         }
        let action2 = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) { (action) in
             print( "用户点击了按钮一" )
         }
        
        let action3 = UIAlertAction(title: "删除", style: UIAlertAction.Style.default) { (action) in
            print( "用户点击了按钮一" )
        }
        
    
         mUIAlertController.addAction( action )
         mUIAlertController.addAction( action2 )
        mUIAlertController.addAction( action3 )
         self.present(mUIAlertController, animated: true) {
             print("完成")
         }
         
    }
    //警告编辑框
    @objc func alert3(){
        
        let mUIAlertController =  UIAlertController(title: "我是警告弹框", message: "这里填写内功", preferredStyle: .alert)
        let action = UIAlertAction(title: "登录", style: UIAlertAction.Style.default) { (action) in
            print( mUIAlertController.textFields?.first?.text ?? "未输入文字" )
        }
        let action2 = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) { (action) in
            print( "取消了" )
        }
        mUIAlertController.addAction( action )
        mUIAlertController.addAction( action2 )
        mUIAlertController.addTextField { (textField) in
            //在闭包中可以对UITextField进行配置
            textField.placeholder = "请输入用户名"
        }
        mUIAlertController.addTextField { (textField)  in
            textField.placeholder = "请输入密码"
            textField.isSecureTextEntry  = true
        }
        
        self.present(mUIAlertController, animated: true) {
            print( "完成..." )
        }
        
        
        
    }
    //创建抽屉弹窗
    @IBAction @objc func alert4(){
        
        
        let mUIAlertController =  UIAlertController(title: "我是警告弹框", message: "这里填写内功", preferredStyle: .actionSheet)
         
         let action = UIAlertAction(title: "确定", style: UIAlertAction.Style.default) { (action) in
             print( "用户点击了按钮一" )
         }
        let action2 = UIAlertAction(title: "取消", style: UIAlertAction.Style.destructive) { (action) in
             print( "用户点击了按钮一" )
         }
        
        let action3 = UIAlertAction(title: "删除", style: UIAlertAction.Style.default) { (action) in
            print( "用户点击了按钮一" )
        }
        
    
         mUIAlertController.addAction( action )
         mUIAlertController.addAction( action2 )
        mUIAlertController.addAction( action3 )
         self.present(mUIAlertController, animated: true) {
             print("完成")
         }
        
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
